package io.github.uicdb.et;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import io.github.uicdb.et.element.BasicElement;
import io.github.uicdb.et.register.ElementalObject;
import io.github.uicdb.et.register.RegisterHelper;
import lombok.Getter;
import net.minecraft.core.Holder;
import net.minecraft.util.StringRepresentable;
import net.neoforged.neoforge.fluids.FluidType;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

@Getter
@SuppressWarnings("all")
public enum ModElements implements StringRepresentable {
    METAL("metal", 0, "\u91d1", 0),
    WOOD("wood", 0, "\u6728", 1),
    WATER("water", 0, "\u6c34", 2),
    FIRE("fire", 0, "\u706b", 3),
    EARTH("earth", 0, "\u571f", 4),
    YIN("yin", 0, "\u9634", 5),
    YANG("yang", 0, "\u9633", 6);
    final ElementalObject elemental;
    final String chinese;
    final int index;
    public static final Codec<ModElements> CODEC = StringRepresentable.fromEnum(ModElements::values);

    public static int index(ModElements elements) {
        return elements.index;
    }

    ModElements(String key, int color, String chinese, int index) {
        this.elemental = RegisterHelper.registerElemental(key, color);
        this.chinese = chinese;
        this.index = index;
    }

    public Holder<BasicElement> holder() {
        return elemental.getElementHolder();
    }

    public static void init() {

    }

    @Nullable
    public static ModElements byHolder(Holder<BasicElement> elements) {
        if (elements.equals(METAL.elemental.getElementHolder())) return METAL;
        if (elements.equals(WOOD.elemental.getElementHolder())) return WOOD;
        if (elements.equals(WATER.elemental.getElementHolder())) return WATER;
        if (elements.equals(FIRE.elemental.getElementHolder())) return FIRE;
        if (elements.equals(EARTH.elemental.getElementHolder())) return EARTH;
        if (elements.equals(YIN.elemental.getElementHolder())) return YIN;
        if (elements.equals(YANG.elemental.getElementHolder())) return YANG;
        return null;
    }

    @Override
    public String getSerializedName() {
        return this.name();
    }
}
